<template>
	<view class="chargeCode">
		<view class="title">
			{{CompanyInfo.Title}}
		</view>
		<tki-qrcode style="margin: 20px 0;" ref="qrcode" :val="xpqrcode" :size="300" unit="upx" />
		<view class="tips">
			使用富盛通小程序
		</view>
		<view class="tips">
			扫一扫上方二维码定位商家
		</view>
		<view class="save">
			<text @click="share">分享给买家</text> <text class="split"></text>
			<text @click="print">打印订货码</text> <text class="split"></text>
			<text @click="savePhoto">保存至相册</text>
		</view>
		<bleConnect ref="bleConnect" :printData="CompanyInfo" v-show="false" type="shopCode" />
	</view>
</template>

<script>
	import bleConnect from '../webview/bleConnect.vue'
	export default {
		components: {
			bleConnect
		},
		data() {
			return {
				CompanyInfo: {},
				xpqrcode: ''
			}
		},
		onLoad() {
			this.CompanyInfo = uni.getStorageSync('CompanyInfo')
			if (!this.CompanyInfo) return
			// 显示二维码区域
			this.xpqrcode = '01,' + this.CompanyInfo.Id
			this.CompanyInfo.code = this.xpqrcode
			setTimeout(() => {
				this.$refs.qrcode._makeCode()
			}, 1)
		},
		methods: {
			print() {
				this.$refs.bleConnect.startSearch()
			},
			savePhoto() {
				this.$refs.qrcode._saveCode()
			},
			async share() {
				uni.showLoading({
					mask: true
				})
				let res = await this.$http('post', '/BO/BillList/GetSzqLink')
				console.log(res);
				uni.hideLoading()
				if (!res.Success) return uni.showToast({
					icon: 'none',
					title: res.Msg
				})
				uni.share({
					provider: "weixin",
					scene: "WXSceneSession",
					type: 5,
					title: this.CompanyInfo.Title + '邀请您赊货', // 分享标题
					imageUrl: "https://www.yoojet.com/fx.jpg", //分享封面图片
					miniProgram: {
						id: 'gh_89ab73bc2bb4',
						// path: 'pages/Home/Home',
						path: 'pages/Login/Login',
						type: '0',
						webUrl: 'https://hzq.yoojet.com'
					},
					success: function(res) {
						// 此处是调起微信分享成功的回调
					},
					fail: function(err) {
						// 此处是调起微信分享失败的回调
						console.log(err);
					}
				});
				// uni.share({
				// 	provider: "weixin",
				// 	scene: "WXSceneSession",
				// 	type: 0,
				// 	title: '赊货签', // 分享标题
				// 	summary: this.CompanyInfo.Title,
				// 	href: res.Data,
				// 	imageUrl: "https://hzq.yoojet.com/wx.png", //分享封面图片
				// 	success: function(res) {
				// 		// 此处是调起微信分享成功的回调
				// 	},
				// 	fail: function(err) {
				// 		// 此处是调起微信分享失败的回调
				// 		console.log(err);
				// 	}
				// });
			}
		}
	}
</script>

<style scoped lang="scss">
	.chargeCode {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
		padding: 20px;
		padding-top: 20vh;

		.tips {
			font-size: 12px;
			color: #333;
		}

		.save {
			position: fixed;
			bottom: 40px;
			width: 100%;
			text-align: center;
			color: #5c6491;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: center;

			.split {
				margin: 0 14px;
				width: 1px;
				border-radius: 1px;
				background-color: #ccc;
				height: 15px;
			}
		}
	}
</style>